package model.db;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name="VerticalResults")
public class VerticalResult implements Serializable {
	private static final long serialVersionUID = -8767341896773261247L;
	
	private long id;
	private long query_id;
	
	private long vertical_id;
	
	private String title;
	private String  snippet;
	private String  thumbnail="";
	
	private String url;
	
	private int rank;
	
	@Column(name="url")
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	
	@Column(name="vertical_id")
	public long getVertical_id() {
		return vertical_id;
	}
	public void setVertical_id(long vertical_id) {
		this.vertical_id = vertical_id;
	}
	
	
	
	@Column(name="rank")
	public int getRank() {
		return rank;
	}
	public void setRank(int rank) {
		this.rank = rank;
	}
	
	
	@Id
	@GeneratedValue
	@Column(name="id")
	public long getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="query_id")
	public long getQuery_id() {
		return query_id;
	}
	public void setQuery_id(long queryId) {
		query_id = queryId;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	
	@Column(name="title")
	public String getTitle() {
		
		if(title !=null) 
		{
			title = cleanCache(title);
			return title.trim();
		}
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column(name="snippet")
	public String getSnippet() {
		
		
		if(snippet!=null) {
			
			snippet = cleanCache(snippet);
			return snippet.trim();
		}
		
		return snippet;
	}
	
	private String cleanCache(String a){
		
		
		if(a.contains("- In cache -")){
			
		a= a.substring(a.indexOf("- In cache -"), a.length());
		
		a=a.replace("- In cache -","");
			
		}
	
		if(a.contains("- In cache")){
			
			a= a.substring(a.indexOf("- In cache"), a.length());
			a=a.replace("- In cache","");
				
			}
		
		a= a.replaceAll("[^\\x00-\\x7F]", "");
		
		return a;
		
	}
	
	public void setSnippet(String snippet) {
		this.snippet = snippet;
	}
	
	@Column(name="thumbnail")
	public String getThumbnail() {
		
		return thumbnail;
	}
	public void setThumbnail(String thumbnail) {
		this.thumbnail = thumbnail;
	}
	

}
